# 配置参数
$SERVER_IP = "101.43.36.81"
$FRONTEND_DIR = ".\frontend"
$BACKEND_DIR = ".\backend"
$JAR_NAME = "qiyeshapan-0.0.1-SNAPSHOT.jar"
$SERVICE_NAME = "qiyeshapan.service"

# 打包前端
Write-Host "Building frontend..."
Set-Location $FRONTEND_DIR
npm install
npm run build
Compress-Archive -Path .\dist -DestinationPath .\dist.zip
scp .\dist.zip ${SERVER_IP}:/opt/
ssh ${SERVER_IP} "rm -rf /opt/dist/* && unzip -o /opt/dist.zip -d /opt/ && rm /opt/dist.zip"
Remove-Item .\dist.zip
Set-Location ..
Write-Host "Frontend deployed!"

# 打包后端
Write-Host "Building backend..."
Set-Location $BACKEND_DIR
mvn clean package -DskipTests
scp .\target\${JAR_NAME} ${SERVER_IP}:/opt/backend/
Set-Location ..
Write-Host "Backend deployed!"

# 重启后端服务
Write-Host "Restarting backend service..."
ssh ${SERVER_IP} "sudo systemctl restart ${SERVICE_NAME}"

Write-Host "Deployment complete! Service status:"
ssh ${SERVER_IP} "sudo systemctl status ${SERVICE_NAME} --no-pager" 